use std::process::Command;

use cross_rs::fasttime::b2_time::TimeFT;



const CMD_7ZA: &str = "7za";

pub fn run_7za_unzip(dir_in: &str, file_7z: &str) {
    
    let start = TimeFT::now();
    let mut cmd_order = Command::new(CMD_7ZA);

    cmd_order
        .current_dir(dir_in)
        .arg("x")
        .arg("-y")
        .arg(format!("./{file_7z}"))
        .arg("-o.");

    match cmd_order.output() {
        Ok(_output) => (),
        Err(e) => error!("run_7za_unzip error: {e:?}, {dir_in}/{file_7z}"),
    }
    let end = TimeFT::now();
    info!("run_7za_unzip: {start}, {:.1} secs; {dir_in}/{file_7z}", end.seconds_from(&start));
}


pub fn run_7za_unzip_many(dir_in: &str, list_file: Vec<String>) {
    let mut arr_thread = vec![];
    for file_7z in list_file {
        let dir_in_copy = dir_in.to_string();
        let t = std::thread::spawn(move || {
            run_7za_unzip(&dir_in_copy, &file_7z);
        });
        arr_thread.push(t);
    }
    for t in arr_thread{
        t.join().unwrap();
    }
}
